<template>
	<uni-loading v-if="loading"></uni-loading>
	<view class="body" v-else>
		<!--  顶部  -->
		<top-tab :options="stockList" :locationName="locationName"
		 :stockNameProp="stockName" @stockChange="stockChange"
			@handleBarnChoose="handleBarnChoose"></top-tab>
			<view class="top-container no-bottom-padding">
				<uni-list :border="false">
					<uni-list-item :border="false" title="单据编号" :rightText="header.fbillno" />
					<uni-list-item :border="false" title="库管" :rightText="header.fstockuser" />
					<uni-list-item :border="false" title="件号" :rightText="detail.fspecification" />
					<!-- <uni-list-item :border="false" title="日期">
						<template v-slot:footer>
							<uni-dateformat :date="header.fdate" format="yyyy年MM月dd日" style="font-size: 20px; color: #000000;">
							</uni-dateformat>
						</template>
					</uni-list-item> -->
				</uni-list>
			</view>
		<!--  列表  -->
		<template v-if="detail">
		
			<uni-swipe-action-item class="" >
				<view class="panel">
		
					<view class="panel_content">
						<view class="panel_content_row">
							<view class="panel_content_row_item">
								<view class="panel_content_row_item_title">件号：</view>
								<view class="panel_content_row_item_value">{{ detail.fspecification }}</view>
								<view class="panel_content_row_item">
									<view class="panel_content_row_item_title">名称：</view>
									<view class="panel_content_row_item_value">{{ detail.fmaterialname }}</view>
								</view>
							</view>
						</view>
					</view>

		
					<view class="panel_content">
						<view class="panel_content_row">
							<view class="panel_content_row_item">
								<view class="panel_content_row_item_title">编码：</view>
								<view class="panel_content_row_item_value">{{ detail.fmaterialno }}</view>
							</view>
							<view class="panel_content_row_item">
								<view class="panel_content_row_item_title">单位：</view>
								<view class="panel_content_row_item_value">{{ detail.funitname }}</view>
							</view>
						</view>
					</view>

					<view class="panel_content">
						<view class="panel_content_row">
							<view class="panel_content_row_item">
								<view class="panel_content_row_item_title">出库数量：</view>
								<view class="panel_content_row_item_value">
									<input v-model="detail.fqty" placeholder="请输入数量"
									
									placeholder-class="input_placeholder"
									style="width: 100px;"
									/>
								</view>
							</view>
							<view class="panel_content_row_item">
								<view class="panel_content_row_item_title">调出仓库：</view>
								<view class="panel_content_row_item_value">{{ detail.fstockname }}</view>
							</view>
						</view>
					</view>
					<view class="panel_content" >
						<view class="panel_content_row">
							<view class="panel_content_row_item">
								<view class="panel_content_row_item_title">调出仓位：</view>
								<view class="panel_content_row_item_value">{{ detail.flocationo }}</view>
								
							</view>
						</view>
					</view>
					<view class="flex-list-btn" >
						<view class="flex-list-btn-item"
						@click="commendLocation(detail)"> 推荐仓位</view>
						<view  class="flex-list-btn-item" 
							@click="scanOrderDe(detail)">
							扫码
						</view>
					</view>
		
				</view>
		
			</uni-swipe-action-item>
		
		</template>
		<uni-empty-info v-else label="暂无物料信息"></uni-empty-info>

		<!--  底部按钮  -->
		<view class="footerPanel">
			<view class="footerPanel_body">
				<button @click="handleScanCode" class="footerBtn scan" type="primary"><i
						class="iconfont icon-saomiao btn_icon"></i>扫码
				</button>
				<button @click="handleSuccess" class="footerBtn save" type="primary"><i
						class="iconfont icon-duihao btn_icon"></i>审核
				</button>
			</view>
		</view>

		<BarnPopup ref="barnPopup" @success="locationScanningSuccess"></BarnPopup>
		<!-- 扫描托盘 -->
		<tray-popup ref="trayPopupRef" @success="trayScanningScuess"></tray-popup>
		<!-- 获取托盘信息 -->
		<!-- <GetTrayTransfer ref="trayRef" @success="getTraySuccess"></GetTrayTransfer> -->
		<!-- 推荐仓位-->
		<Commend ref="commendRef" ></Commend>
	</view>
</template>
<script>
	import Commend from "@/pages/pop/commend-scan.vue"
	import trayPopup from '../../components/popup/trayPopup.vue'
	import topTab from "@/components/top-tab/top-tab"
	import GetTrayTransfer from "../pop/get_tray_transferApp.vue"
	import uniLoading from "../../vBase/components/uni-loading/uni-loading"
	import uniEmptyInfo from "../../vBase/components/uni-empty-info/uni-empty-info"
	import BarnPopup from "@/components/popup/barnPopup"
	import{getStockListByUser,
	getStkTransferAppDetail,
	auditStkTransferAppBaoCai,
	getTrayTransfer,
	commendLocation,
	deleteTransferTemp
		}  from  '@/utils/api.js'
	export default {
		components: {
			topTab,
			uniLoading,
			uniEmptyInfo,
			BarnPopup,
			trayPopup,
			Commend,
			GetTrayTransfer
		},
		data() {
			return {
				loading: false,
				purchaseList: [],
				options: [{
					text: '删除',
					style: {
						backgroundColor: '#FF4E74'
					}
				}],
				detailId : '',
				fid : '',
				scaningShow: false,
				scanNo: null,
				isFouce: false,
				stockList: [],
				stockNo: '',
				stockName:'',
				locationNo: '',
				locationName: '',
				commedList :[],
				header:{},//调拨申请单据头
				detail:{},//调拨申请明细
				sourceStockNo: null,
				sourceLocationNo: null
			}
		},
		/**
		 * 返回指定页面(onBackPress函数放置)
		 *
		 * @param e
		 */
		onLoad(e) {
		
			this.detailId = e.detailId

			
			// 获取详情数据
			// this.initData()
		
		},
		onUnload() {
			uni.$off('deleteItem');
		},
		mounted() {
			this.getStockList()
			this.initData()
		},
		methods: {
		
			/** 扫码 */
			handleScanCode() {
	
				this.$refs.trayPopupRef.open()
			},
			/**
			 * 推荐仓位
			 */
			commendLocation(item){
					let self = this;
					commendLocation({
						materialNo : item.fmaterialno
					}).then(res =>{
						if (res.data.status == 200){
							self.commedList = res.data.data.dataList ?? []
							
						} 
						let param = {
							dataList : self.commedList
						}
			
						this.$refs.commendRef.open(param)
					})
			},
			//扫码成功后返回
			trayScanningScuess(e){
				this.detail.flocationo = e
				
			},
			//扫描调出仓位，扫描成功后修改下拉框中仓位信息
			scanOrderDe(item) {

				this.$refs.trayPopupRef.open()
				
			},
			//仓位扫码成功后返回
			locationScanningSuccess(e){
				this.locationNo =e
				this.locationName =e
				
			},
			/** 查询仓库*/
			getStockList() {
				getStockListByUser({}).then(res =>{
					this.stockList = res.data.data.dataList
				})
			},
			/** 初始化数据 */
			initData() {
				
				this.getDataList()
			},

			/** 获取数据 */
			getDataList() {
				getStkTransferAppDetail({detailId :this.detailId}).then(res =>{
					// this.purchaseList =  res.data.data.dataList
					this.header = res.data.data.data
					this.detail = res.data.data.detail
					this.stockNo = res.data.data.detail.fstockinno
					this.stockName = res.data.data.detail.fstockinname
				})
			},

			/** 完成新增 */
			async handleSuccess() {
				try {
		
					if (!this.stockNo) {
						uni.showToast({
							title: '请选择仓库',
							icon: 'none'
						});
						return;
					}
			
					let param = {
						stockNo : this.stockNo,
						locationNo : this.locationNo,
						detail : this.detail
					}
					uni.showModal({
						title:'提示',
						content:'确认审核',
						success(res) {
							if (res.confirm){
								auditStkTransferAppBaoCai(param).then(res =>{
									if (res.data.status == 200){
										uni.showToast({
											title: "调拨完成",
											icon: "none"
										})
										setTimeout(() => {
											uni.navigateBack({
												delta:1
											})
										}, 2000)
									}
								})
							}
						}
					})
					
					
				} finally {}

			},

	

			/**
			 * 选择仓库
			 * @param e
			 */
			stockChange(e) {
				this.stockNo = this.stockList[e].stockNo
			
			},

			/**
			 * 选择仓位
			 * @param e
			 */
			stockLocation(e) {
				this.locationNo = e.locationNo
				this.locationName = e.locationName
			},

			/**
			 * 选择
			 */
			handleBarnChoose() {
				this.$refs.barnPopup.open();
			},


			

		}
	}
</script>
<style lang="scss" scoped>
	@import "../../static/css/common";
</style>
